Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cson-safe

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cson-safe

Safe parsing of CSON files

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

cson-safe

An alternative to cson. Advantages of cson-safe:

  • A strict subset of CSON that allows only data
  • Interface is identical to JSON.{parse,stringify}
  • Does not run the code, free of intermediate string representations
  • Sane parse error messages with line/column

In addition of pure data it allows for simple arithmetic expressions like addition and multiplication. This allows more readable configuration of numbers, the following is a valid strict CSON file:

cachedData:
  refreshIntervalMs: 5 * 60 * 1000

Install

npm install --save cson-safe

Usage

CSON = require 'cson-safe'
# This will print { a: '123' }
console.log CSON.parse "a: '123'"

High-level APIs

cson-safe only offers basic parsing and serialization. But there are some great tools if you want more than that:

  • season, atom.io's CSON package. Includes CLI tool to convert CSON to JSON
  • grunt-cson, converts CSON to JSON as a grunt task
  • load-grunt-configs, loads grunt config from CSON files (among other formats)
  • fetcher, a declarative way to download (frontend) libraries, supports CSON configs
  • csonschema, parses JSON Schema files written in CSON

You can find more on the npm website.

FAQ

Why not just use YAML?

YAML allows for some pretty complex constructs like anchor and alias, which can behave in unexpected ways, especially with nested objects. CSON is simpler while still offering most of the niceties of YAML.

Why not just use JSON?

JSON doesn't offer multi-line strings and is generally a little noisier. Also sometimes it can be nice to have comments in config files.

Why not just use CoffeeScript directly?

You don't want data files being able to run arbitrary code. Even when ran in a proper sandbox, while(true) is still possible.

Keywords

Package last updated on 29 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc